package be.destin.adp;

import java.util.ArrayList;
import java.util.regex.Matcher;

public class AdpTransformationExec {
	AdpExec envExec;
	AdpTransformation transformation;
	ArrayList<Matcher> matchers = new ArrayList<Matcher>();
	
	AdpTransformationExec(AdpExec envExec, AdpTransformation transformation) {
		this.envExec = envExec;
		this.setTransformation(transformation);
	}

	/**
	 * @return the envExec
	 */
	public AdpExec getEnvExec() {
		return envExec;
	}

	/**
	 * @param envExec the envExec to set
	 */
	public void setEnvExec(AdpExec envExec) {
		this.envExec = envExec;
	}

	/**
	 * @return the transformation
	 */
	public AdpTransformation getTransformation() {
		return transformation;
	}

	/**
	 * @param transformation the transformation to set
	 */
	public void setTransformation(AdpTransformation transformation) {
		this.transformation = transformation;
		this.matchers = new ArrayList<Matcher>(transformation.rules.size());
		int index = 0;
		for (AdpRule aRule: transformation.rules) {
			Matcher aMatcher = aRule.getPattern().matcher( "xxxx");
			this.matchers.set(index, aMatcher);
			index++;
		}
	}

	/**
	 * @return the matchers
	 */
	public ArrayList<Matcher> getMatchers() {
		return matchers;
	}

	/**
	 * @return the matchers
	 */
	public String getVar(String name) {
		return matchers.get(matchers.size()-1).group(name);
	}

	/**
	 * @param matchers the matchers to set
	 */
	public void setMatchers(ArrayList<Matcher> matchers) {
		this.matchers = matchers;
	}
	
}
